package com.woniu.payback_font.web;

import com.github.pagehelper.PageInfo;
import com.woniu.payback_font.result.ResponseResult;
import com.woniu.payback_font.service.UserMessageService;
import com.woniu.payback_font.vo.IsOkVo;
import com.woniu.payback_font.vo.UserMessageVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api("UserManager接口Api")
@RequestMapping("userManager")
public class UserManagerController {

    @Autowired
    UserMessageService userMessageService;



    @GetMapping("/showUserManager")
    public ResponseResult<PageInfo<UserMessageVo>> showUserManager(String umName, String uMobile, String umIdcard,
                                                                @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                                                @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize){
        PageInfo<UserMessageVo> pageInfo = userMessageService.findByNameAndModilAndidCrid(umName,uMobile,umIdcard,pageNum,pageSize);
        ResponseResult<PageInfo<UserMessageVo>> result = new ResponseResult<>(200,"查询成功");
        result.setData(pageInfo);
        return result;
    }


    @GetMapping("/showOneUserManager/{umId}")
    public ResponseResult<UserMessageVo> showOneUserManager(@PathVariable("umId") Integer umId){
        UserMessageVo userMessageVo= userMessageService.findOneUserManager(umId);
        ResponseResult<UserMessageVo> result = new ResponseResult<>(200,"查询成功");
        result.setData(userMessageVo);
        return result;
    }

    @PutMapping("/userisOK")
    public ResponseResult<UserMessageVo> userisOK(@RequestBody IsOkVo isOkVo){
        ResponseResult<UserMessageVo> result=null;
        if(isOkVo.getUmIspass()==0){//拒绝通过审核，请求失败更新t_user_message状态
           int i= userMessageService.userNO(isOkVo);
           if (i>0){
                result = new ResponseResult<>(200,"审批成功");
           }else{
                result = new ResponseResult<>(204,"未知错误，请重新审核");
           }
        }else if(isOkVo.getUmIspass()==2){//审核通过，更新t_user_message ，t_account两张表的字段
            int i= userMessageService.userOk(isOkVo);
            if (i>0){
                 result = new ResponseResult<>(200,"审批成功");
            }else{
                 result = new ResponseResult<>(204,"未知错误，请重新审核");
            }
        }
        return result;
    }
}
